package com.lanou.musicproject.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.lanou.musicproject.R;


/**
 * Created by dllo on 15/10/20.
 * 音乐馆左侧页面
 */
public class LeftFragment extends Fragment implements View.OnClickListener {

    private Button  c_man, c_woman, c_group, w_man, w_woman, w_group, k_man, k_woman, k_group;
    private ToRightFragment listener;
    private Button top;

    // 自定义接口
    public interface ToRightFragment {
        void onToRightListener(int index);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        listener = (ToRightFragment) context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View leftView = inflater.inflate(R.layout.fragment_left, null);
        initView(leftView);

        return leftView;
    }

    // 加载布局
    private void initView(View v) {
        top = (Button) v.findViewById(R.id.fl_top);
        // 华语
        c_man = (Button) v.findViewById(R.id.fl_china_man);
        c_woman = (Button) v.findViewById(R.id.fl_china_woman);
        c_group = (Button) v.findViewById(R.id.fl_china_group);
        // 欧美
        w_man = (Button) v.findViewById(R.id.fl_west_man);
        w_woman = (Button) v.findViewById(R.id.fl_west_woman);
        w_group = (Button) v.findViewById(R.id.fl_west_group);

        // 日韩
        k_man = (Button) v.findViewById(R.id.fl_korea_man);
        k_woman = (Button) v.findViewById(R.id.fl_korea_woman);
        k_group = (Button) v.findViewById(R.id.fl_korea_group);

        top.setOnClickListener(this);
        c_man.setOnClickListener(this);
        c_woman.setOnClickListener(this);
        c_group.setOnClickListener(this);
        w_man.setOnClickListener(this);
        w_woman.setOnClickListener(this);
        w_group.setOnClickListener(this);
        k_man.setOnClickListener(this);
        k_woman.setOnClickListener(this);
        k_group.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.fl_top://top100
                listener.onToRightListener(0);
                break;
            case R.id.fl_china_man:// 华语男
                listener.onToRightListener(1);
                break;
            case R.id.fl_china_woman:
                listener.onToRightListener(2);
                break;
            case R.id.fl_china_group:
                listener.onToRightListener(3);
                break;
            case R.id.fl_west_man:// 欧美男
                listener.onToRightListener(4);
                break;
            case R.id.fl_west_woman:
                listener.onToRightListener(5);
                break;
            case R.id.fl_west_group:
                listener.onToRightListener(6);
                break;
            case R.id.fl_korea_man:// 日韩男
                listener.onToRightListener(7);
                break;
            case R.id.fl_korea_woman:
                listener.onToRightListener(8);
                break;
            case R.id.fl_korea_group:
                listener.onToRightListener(9);
                break;
        }
    }

}
